// 重写RowEditor
Ext.override(Ext.ux.grid.RowEditor, {
	saveText: '提交',
	cancelText: '退出',
	//clicksToEdit: 2,
	errorSummary: false,
	monitorValid: false,
	initComponent: function () {
		Ext.ux.grid.RowEditor.superclass.initComponent.call(this);
		this.addEvents('beforerecordsubmit',
		/**
		* @event beforeedit Fired before the row editor is activated.
		*        If the listener returns <tt>false</tt> the editor
		*        will not be activated.
		* @param {Ext.ux.grid.RowEditor}
		*            roweditor This object
		* @param {Number}
		*            rowIndex The rowIndex of the row just edited
		*/
				'beforeedit',
		/**
		* @event canceledit Fired when the editor is cancelled.
		* @param {Ext.ux.grid.RowEditor}
		*            roweditor This object
		* @param {Boolean}
		*            forced True if the cancel button is pressed, false
		*            is the editor was invalid.
		*/
				'canceledit',
		/**
		* @event validateedit Fired after a row is edited and passes
		*        validation. If the listener returns <tt>false</tt>
		*        changes to the record will not be set.
		* @param {Ext.ux.grid.RowEditor}
		*            roweditor This object
		* @param {Object}
		*            changes Object with changes made to the record.
		* @param {Ext.data.Record}
		*            r The Record that was edited.
		* @param {Number}
		*            rowIndex The rowIndex of the row just edited
		*/
				'validateedit',
		/**
		* @event afteredit Fired after a row is edited and passes
		*        validation. This event is fired after the store's
		*        update event is fired with this edit.
		* @param {Ext.ux.grid.RowEditor}
		*            roweditor This object
		* @param {Object}
		*            changes Object with changes made to the record.
		* @param {Ext.data.Record}
		*            r The Record that was edited.
		* @param {Number}
		*            rowIndex The rowIndex of the row just edited
		*/
				'afteredit');
	},
	startEditing: function (rowIndex, doFocus) {
		if (this.editing && this.isDirty()) {
			// this.showTooltip(this.commitChangesText);章弦修改
			return;
		}
		if (Ext.isObject(rowIndex)) {
			rowIndex = this.grid.getStore().indexOf(rowIndex);
		}
		if (this.fireEvent('beforeedit', this, rowIndex) !== false) {
			this.editing = true;
			var g = this.grid, view = g.getView(), row = view.getRow(rowIndex), record = g.store
					.getAt(rowIndex);

			this.record = record;
			this.rowIndex = rowIndex;
			this.values = {};
			if (!this.rendered) {
				this.render(view.getEditorParent());
			}
			var w = Ext.fly(row).getWidth();
			this.setSize(w);
			if (!this.initialized) {
				this.initFields();
			}
			// zhangxian添加 判断编辑只读用开始
			var datacount = 0;
			for (f in record.data) {
				datacount++;
			}
			// 结束
			var cm = g.getColumnModel(), fields = this.items.items, f, val;
			for (var i = 0, len = cm.getColumnCount(); i < len; i++) {
				// zhangxian添加 判断编辑只读用开始
				var c = cm.getColumnAt(i);
				var ed = this.get(i);
				if (c.updateEdit == false && datacount > 0) {
					ed.disable();
				} else {
					ed.enable();
				}
				// 结束
				val = this.preEditValue(record, cm.getDataIndex(i));
				if (!cm.isCellEditable(i, this.rowIndex) && cm.columns != undefined && c.id != 'numberer' && c.dataIndex != undefined) {
					val = cm.getRenderer(i)(val);
				}
				f = fields[i];
				f.setValue(val);
				this.values[f.id] = Ext.isEmpty(val) ? '' : val;
			}
			this.verifyLayout(true);
			if (!this.isVisible()) {
				this.setPagePosition(Ext.fly(row).getXY());
			} else {
				this.el.setXY(Ext.fly(row).getXY(), {
					duration: 0.15
				});
			}
			if (!this.isVisible()) {
				this.show().doLayout();
			}
			if (doFocus !== false) {
				this.doFocus.defer(this.focusDelay, this);
			}
		}
	},
	stopEditing: function (saveChanges) {
		this.editing = false;
		if (!this.isVisible()) {
			return;
		}
		if (saveChanges === false || !this.isValid()) {
			this.hide();
			this.fireEvent('canceledit', this, saveChanges === false);
			return;
		}
		var changes = {}, r = this.record, hasChange = false, cm = this.grid.colModel, fields = this.items.items;
		for (var i = 0, len = cm.getColumnCount(); i < len; i++) {
			if (!cm.isHidden(i) && cm.isCellEditable(i, this.rowIndex)) {
				var dindex = cm.getDataIndex(i);
				if (!Ext.isEmpty(dindex)) {
					var oldValue = r.data[dindex], value = this.postEditValue(
							fields[i].getValue(), oldValue, r, dindex);
					if (String(oldValue) !== String(value)) {
						changes[dindex] = value;
						hasChange = true;
					}
				}
			}
		}
		if (hasChange && this.fireEvent('validateedit', this, changes, r, this.rowIndex) !== false) {
			r.beginEdit();
			Ext.iterate(changes, function (name, value) {
				r.set(name, value);
			});
			this.fireEvent('beforerecordsubmit', r, cm, this.rowIndex);
			r.endEdit();
			this.fireEvent('afteredit', this, changes, r, this.rowIndex);
		}
		this.hide();
	},
	save: function (isSave) {
		if (!this.isValid())
			return;
		this.stopEditing(this, isSave);
	},
	onRender: function () {
		Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
		this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
		this.btns = new Ext.Panel({
			baseCls: 'x-plain',
			cls: 'x-btns',
			elements: 'body',
			layout: 'table',
			width: (this.minButtonWidth * 2) + (this.frameWidth * 2)
							+ (this.buttonPad * 4), // width must be specified
			// for IE
			items: [{
				ref: 'saveBtn',
				itemId: 'saveBtn',
				xtype: 'button',
				text: this.saveText,
				width: this.minButtonWidth,
				handler: this.save.createDelegate(this, [true])
			}, {
				xtype: 'button',
				text: this.cancelText,
				width: this.minButtonWidth,
				handler: this.stopEditing.createDelegate(this, [false])
			}]
		});
		this.btns.render(this.bwrap);
	}
});

//Ext.grid.CheckboxSelectionModel
Ext.override(Ext.grid.CheckboxSelectionModel, {
	initComponent: function () {
		Ext.grid.CheckboxSelectionModel.superclass.initComponent.call(this);
	},
	// editor colmode...
	getEditor: function () {
		return false;
	}
});